package jt.classic.system.workflow.impl;

import jt.classic.system.wordbook.XWordbook;
import jt.classic.system.wordbook.XWordbookMain;
import jt.classic.system.wordbook.XWordbookQuery;
import jt.classic.system.workflow.WNumber;

import org.limp.basework.AbstractSimpleBean;

import java.util.Map;


/**
 * 流程实例编号接口实现�?
 *
 * @author bizkit
 *
 */
public class WNumberImpl extends AbstractSimpleBean implements WNumber {
    private String key;
    private String prefix;
    private String sequence;
    private String suffix;
    private String value;
    private String objkey;
    private int used;
    private Map numbermap;

    public String ikey() {
        // TODO Auto-generated method stub
        return this.key;
    }

    public String ikeylabel() {
        // TODO Auto-generated method stub
        String temp = this.key;

        String label = ((this.numbermap != null) &&
            this.numbermap.containsKey(temp))
            ? (String) this.numbermap.get(temp) : "";

        return label;
    }

    public String ilabel(int size) {
        // TODO Auto-generated method stub
        String result = "";
        int s = size - this.value.length();

        for (int i = 0; i < s; i++) {
            result += "0";
        }

        result += this.value;

        return result;
    }

    public String iprefix() {
        // TODO Auto-generated method stub
        return this.prefix;
    }

    public String isequence() {
        // TODO Auto-generated method stub
        return this.sequence;
    }

    public String isuffix() {
        // TODO Auto-generated method stub
        return this.suffix;
    }

    public String ivalue() {
        // TODO Auto-generated method stub
        return this.value;
    }

    public boolean used() {
        return this.used == 1;
    }

    public void reload(Map info) {
        if (info != null) {
            this.info = info;

            this.key = (String) info.get("PKID");
            this.value = (String) info.get("NUM_VALUE");
            this.prefix = (String) info.get("NUM_PREFIX");
            this.suffix = (String) info.get("NUM_SUFFIX");
            this.sequence = (String) info.get("INS_SEQUENCE");

            this.used = Integer.parseInt((String) info.get("ONUSE"));

            this.numbermap = (Map) info.get("NUMBERMAP");

            this.objkey = (String) info.get("OBJKEY");
        }
    }
}
